package main

import (
	"fmt"
	"io"
	"net/http"
	"strings"
	"time"
)

func dataGetAppend(val string, sb *strings.Builder) {
	sb.WriteString(val + "=")
	htmlBd := dataBody(val)
	sb.WriteString(htmlBd)
	if strings.Index(htmlBd, `name_r`) > 0 {
		htmlBd = htmlBd[strings.Index(htmlBd, `name_r`):]
		htmlBd = strBodyEnd(htmlBd, " target=")
		htmlBd = strBodsStart(htmlBd, " href=")
		sb.WriteString(htmlBd)
		sb.WriteRune('\n')
	}
}

func dataBody(val string) string {
	webUrl := fmt.Sprintf("http://www.world68.com/show.asp?id=%s", val)
	vd, err := http.Get(webUrl)
	if err != nil {
		fmt.Print(err)
		return ""
	}
	bd, err := io.ReadAll(vd.Body)
	if err != nil {
		fmt.Print(err)
		return ""
	}
	htmlBd := string(bd)
	return htmlBd
}
func strBodsStart(str, start string) string {
	if strings.Index(str, start) > 0 {
		return str[strings.Index(str, start)+len(start):]
	}
	return ""
}
func strBodyEnd(str, end string) string {
	if strings.Index(str, end) > 0 {
		return str[:strings.Index(str, end)]
	}
	return ""
}

func dataGet233(sb *strings.Builder) {
	for i := 1; i <= 233; i++ {
		webUrl := fmt.Sprintf("http://www.world68.com/top.asp?t=5star&page=%d", i)
		fmt.Print("\n")
		fmt.Print(webUrl, "start")
		vd, err := http.Get(webUrl)
		if err != nil {
			fmt.Print(err)
			continue
		}
		bd, err := io.ReadAll(vd.Body)
		if err != nil {
			fmt.Print(err)
			continue
		}
		time.Sleep(3 * time.Second)
		fmt.Print("sleep 3 second")
		//ulistData := string(vd)
		arrayList := strings.Split((string)(bd), "orld68.com/show.asp?id=")
		for iindex, i3 := range arrayList {
			fmt.Print("arrayList.length", iindex, len(arrayList), i3)
			if strings.Index(i3, `">`) > 0 {

				vd := i3[:strings.Index(i3, `">`)]
				bl := true
				for _, i5 := range vd {
					if i5 >= '0' && i5 <= '9' {

					} else {
						bl = false
						break
					}
				}
				if bl {
					sb.WriteString(vd)
					sb.WriteRune('\n')
				}
			}
		}
	}
}
